#include "CCrackedWall.h"
#include "CCamera.h"
#include "SGD Wrappers/CSGD_Direct3D.h"
#include "SGD Wrappers/CSGD_DirectInput.h"
#include "CGame.h"
#include "CPlayer.h"

CCrackedWall::CCrackedWall()
{
	m_nType = OBJ_CRACK;
	SetWidth(64);
	SetHeight(64);

	m_bPlayerTouching = false;
}

void CCrackedWall::Update(float fElapsedTime)
{
	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_3) && m_bPlayerTouching)
	{
		m_pPlayer->SetPosX(m_pConnected->GetPosX() + m_pConnected->GetWidth()/2);
		m_pPlayer->SetPosY(m_pConnected->GetPosY() + m_pConnected->GetHeight()/2);

	}
}

void CCrackedWall::Render()
{
	if((CCamera::GetInstance()->GetCameraPosX() < (GetPosX() + GetWidth())) && (CCamera::GetInstance()->GetCameraPosY() < (GetPosY() + GetHeight())) &&
		((CCamera::GetInstance()->GetCameraPosX() + CGame::GetInstance()->GetScreenWidth()) > GetPosX()) &&
		((CCamera::GetInstance()->GetCameraPosY() + CGame::GetInstance()->GetScreenHeight()) > GetPosY()))
	{
		RECT temp = GetCollisionRect();
		temp.top -= CCamera::GetInstance()->GetCameraPosY();
		temp.left -= CCamera::GetInstance()->GetCameraPosX();
		temp.bottom -= CCamera::GetInstance()->GetCameraPosY();
		temp.right -= CCamera::GetInstance()->GetCameraPosX();
		CSGD_Direct3D::GetInstance()->DrawRect(temp, 0,0,0);
	}

}
bool CCrackedWall::CheckCollision(CBase* pBase)
{
	m_bPlayerTouching = false;

	if(pBase->GetType() == OBJ_PLAYER)
	{
		if(IntersectRect(&RECT(), &GetCollisionRect(), &pBase->GetCollisionRect()))
		{
			m_bPlayerTouching = true;
			return true;
		}
	}

	return false;
}